package info.sean.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    private static  final  String DATE_PATTERN = "yyyy-MM-dd";
    public static final String DATE_PATTERN_SS = "yyyy-MM-dd HH:mm:ss";

    public static Date getTodayMorning() {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
        String morningStr = dateFormat.format(new Date());
        try {
            return dateFormat.parse(morningStr);
        } catch (ParseException e) {
            return null;
        }
    }
    public static Date getDate(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
        String morningStr = dateFormat.format(date);
        try {
            Date parse = dateFormat.parse(morningStr);
            return parse;
        } catch (ParseException e) {
            return null;
        }
    }
    public static String getDateString(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN_SS);
        String morningStr = dateFormat.format(date);
        return morningStr;

    }
    /**
     * 通过传入的时间，返回yyyy-MM-dd 00:00:00格式
     * @param date
     * @return
     */
    public static Date getDateUtil(Date date) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
        // 将时分秒,毫秒域清零
        cal1.set(Calendar.HOUR_OF_DAY, 0);
        cal1.set(Calendar.MINUTE, 0);
        cal1.set(Calendar.SECOND, 0);
        cal1.set(Calendar.MILLISECOND, 0);
        return cal1.getTime();
    }

}
